//
//  TwoTabViewCell.m
//  ProjectA_LK
//
//  Created by 萌萌的小坤坤 on 16/6/16.
//  Copyright © 2016年 冷坤. All rights reserved.
//

#import "TwoTabViewCell.h"
#import "ProjectCollectionCell.h"
#import "UIImageView+WebCache.h"
@implementation TwoTabViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self creatCollectionView];
    }
    return self;
}
- (void)creatCollectionView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(([UIScreen mainScreen].bounds.size.width - 50) / 3,100);
    flowLayout.sectionInset = UIEdgeInsetsMake(0,10 ,0, 10);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 10,[UIScreen mainScreen].bounds.size.width, 120) collectionViewLayout:flowLayout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_collectionView];
    
    [self.collectionView registerClass:[ProjectCollectionCell class] forCellWithReuseIdentifier:@"projectCell"];
    [_collectionView release];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.myArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    ProjectCollectionCell *item = [collectionView dequeueReusableCellWithReuseIdentifier:@"projectCell" forIndexPath:indexPath];
    [item.picView sd_setImageWithURL:[NSURL URLWithString:self.myArray[indexPath.item]]];
    return item;
}

- (void)setDataSource:(NSArray *)dataSource{
    _dataSource = dataSource;
    self.myArray = [NSArray arrayWithArray:dataSource];
    [self.collectionView reloadData];
}


@end
